#! /usr/bin/env python
#*
#*  Copyright (c) 2010, Jack O'Quin
#*  All rights reserved.
#*
#*  Redistribution and use in source and binary forms, with or without
#*  modification, are permitted provided that the following conditions
#*  are met:
#*
#*   * Redistributions of source code must retain the above copyright
#*     notice, this list of conditions and the following disclaimer.
#*   * Redistributions in binary form must reproduce the above
#*     copyright notice, this list of conditions and the following
#*     disclaimer in the documentation and/or other materials provided
#*     with the distribution.
#*   * Neither the name of the author nor the names of other
#*     contributors may be used to endorse or promote products derived
#*     from this software without specific prior written permission.
#*
#*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
#*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
#*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
#*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
#*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#*  POSSIBILITY OF SUCH DAMAGE.
#***********************************************************

# 1394 camera dynamic configuration

PACKAGE='camera1394_asl'
import roslib; roslib.load_manifest(PACKAGE)

from dynamic_reconfigure.parameter_generator import *
from driver_base.msg import SensorLevels


gen = ParameterGenerator()

#       Name, Type, Reconfiguration level, Description, Default, Min, Max

gen.add("guid", str_t, SensorLevels.RECONFIGURE_CLOSE,
        "Global Unique ID of camera, 16 hex digits (use first camera if null).",
        "")

modes = gen.enum([gen.const("Format0_Mode0", str_t, "160x120_yuv444", ""),
                  gen.const("Format0_Mode1", str_t, "320x240_yuv422", ""),
                  gen.const("Format0_Mode2", str_t, "640x480_yuv411", ""),
                  gen.const("Format0_Mode3", str_t, "640x480_yuv422", ""),
                  gen.const("Format0_Mode4", str_t, "640x480_rgb8", ""),
                  gen.const("Format0_Mode5", str_t, "640x480_mono8", ""),
                  gen.const("Format0_Mode6", str_t, "640x480_mono16", ""),
                  gen.const("Format1_Mode0", str_t, "800x600_yuv422", ""),
                  gen.const("Format1_Mode1", str_t, "800x600_rgb8", ""),
                  gen.const("Format1_Mode2", str_t, "800x600_mono8", ""),
                  gen.const("Format1_Mode6", str_t, "800x600_mono16", ""),
                  gen.const("Format1_Mode3", str_t, "1024x768_yuv422", ""),
                  gen.const("Format1_Mode4", str_t, "1024x768_rgb8", ""),
                  gen.const("Format1_Mode5", str_t, "1024x768_mono8", ""),
                  gen.const("Format1_Mode7", str_t, "1024x768_mono16", ""),
                  gen.const("Format2_Mode0", str_t, "1280x960_yuv422", ""),
                  gen.const("Format2_Mode1", str_t, "1280x960_rgb8", ""),
                  gen.const("Format2_Mode2", str_t, "1280x960_mono8", ""),
                  gen.const("Format2_Mode6", str_t, "1280x960_mono16", ""),
                  gen.const("Format2_Mode3", str_t, "1600x1200_yuv422", ""),
                  gen.const("Format2_Mode4", str_t, "1600x1200_rgb8", ""),
                  gen.const("Format2_Mode5", str_t, "1600x1200_mono8", ""),
                  gen.const("Format2_Mode7", str_t, "1600x1200_mono16", ""),
                  gen.const("Format7_Mode0", str_t, "format7_mode0", ""),
                  gen.const("Format7_Mode1", str_t, "format7_mode1", ""),
                  gen.const("Format7_Mode2", str_t, "format7_mode2", ""),
                  gen.const("Format7_Mode3", str_t, "format7_mode3", ""),
                  gen.const("Format7_Mode4", str_t, "format7_mode4", ""),
                  gen.const("Format7_Mode5", str_t, "format7_mode5", ""),
                  gen.const("Format7_Mode6", str_t, "format7_mode6", ""),
                  gen.const("Format7_Mode7", str_t, "format7_mode7", ""),
                  ],
                 "Video mode for camera.")

gen.add("video_mode", str_t, SensorLevels.RECONFIGURE_CLOSE,
        "IIDC video mode.", "640x480_mono8", edit_method = modes)

gen.add("frame_id", str_t, SensorLevels.RECONFIGURE_CLOSE,
        "ROS tf frame of reference, resolved with tf_prefix unless absolute.",
        "camera")

gen.add("frame_rate", double_t, SensorLevels.RECONFIGURE_CLOSE,
        "Camera speed (frames per second).", 15.0, 1.875, 240.0)

gen.add("iso_speed", int_t, SensorLevels.RECONFIGURE_CLOSE,
        "Total IEEE 1394 bus bandwidth (Megabits/second).", 400, 100, 3200)

gen.add("camera_info_url", str_t, SensorLevels.RECONFIGURE_RUNNING,
        "Camera [[camera_info_manager#URL_Names|calibration URL]] for this video_mode (uncalibrated if null).", "")

gen.add("reset_on_open", bool_t, SensorLevels.RECONFIGURE_CLOSE,
        "Reset camera when opening the device.", False)

gen.add("use_ros_time", bool_t, SensorLevels.RECONFIGURE_CLOSE,
        "Timestamp Image and CameraInfo using ros::Time::now()", False)

# Format7-specific parameters
gen.add("binning_x", int_t, SensorLevels.RECONFIGURE_CLOSE,
        "Number of pixels combined for Format7 horizontal binning, use device hints if zero.",
        0, 0, 4)

gen.add("binning_y", int_t, SensorLevels.RECONFIGURE_CLOSE,
        "Number of pixels combined for Format7 vertical binning, use device hints if zero.",
        0, 0, 4)

gen.add("roi_width", int_t, SensorLevels.RECONFIGURE_CLOSE,
        "Width of Format7 Region of Interest in unbinned pixels, full width if zero.",
        0, 0, 65535)

gen.add("roi_height", int_t, SensorLevels.RECONFIGURE_CLOSE,
        "Height of Format7 Region of Interest in unbinned pixels, full height if zero.",
        0, 0, 65535)

gen.add("x_offset", int_t, SensorLevels.RECONFIGURE_CLOSE,
        "Horizontal offset for left side of Format7 ROI in unbinned pixels.",
        0, 0, 65535)

gen.add("y_offset", int_t, SensorLevels.RECONFIGURE_CLOSE,
        "Vertical offset for top of Format7 ROI in unbinned pixels.",
        0, 0, 65535)

gen.add("format7_packet_size", int_t, SensorLevels.RECONFIGURE_CLOSE,
        "Format7 packet size (bytes), device-recommended size if zero.",
        0, 0, 39320)

codings = gen.enum([gen.const("mono8", str_t, "mono8", ""),
                    gen.const("mono16", str_t, "mono16", ""),
                    gen.const("mono16s", str_t, "mono16s", ""),
                    gen.const("raw8", str_t, "raw8", ""),
                    gen.const("raw16", str_t, "raw16", ""),
                    gen.const("rgb8", str_t, "rgb8", ""),
                    gen.const("rgb16", str_t, "rgb16", ""),
                    gen.const("rgb16s", str_t, "rgb16s", ""),
                    gen.const("yuv411", str_t, "yuv411", ""),
                    gen.const("yuv422", str_t, "yuv422", ""),
                    gen.const("yuv444", str_t, "yuv444", "")],
                    "Format7 color coding methods")

gen.add("format7_color_coding", str_t, SensorLevels.RECONFIGURE_CLOSE,
        "Color coding (only for Format7 modes)", "mono8",
        edit_method = codings)

# Bayer color filter parameters
patterns = gen.enum([gen.const("none", str_t, "", "No Bayer encoding"),
                     gen.const("rggb", str_t, "rggb", ""),
                     gen.const("gbrg", str_t, "gbrg", ""),
                     gen.const("grbg", str_t, "grbg", ""),
                     gen.const("bggr", str_t, "bggr", "")],
                    "Bayer color encoding patterns")

gen.add("bayer_pattern", str_t, SensorLevels.RECONFIGURE_CLOSE,
        "Bayer color encoding pattern (default: none).", "",
        edit_method = patterns)

methods = gen.enum([gen.const("image_proc", str_t, "",
                              "Decode via ROS image_proc"),
                    gen.const("DownSample", str_t, "DownSample", ""),
                    gen.const("Simple", str_t, "Simple", ""),
                    gen.const("Bilinear", str_t, "Bilinear", ""),
                    gen.const("HQ", str_t, "HQ", ""),
                    gen.const("VNG", str_t, "VNG", ""),
                    gen.const("AHD", str_t, "AHD", "")],
                   "Bayer method")

gen.add("bayer_method", str_t, SensorLevels.RECONFIGURE_CLOSE,
        "Bayer decoding method (default: ROS image_proc).",
        "", edit_method = methods)

# Generic IIDC feature control states, not all apply.
controls = gen.enum([gen.const("Off", int_t, 0, "Use fixed value"),
                     gen.const("Query", int_t, 1, "Query current values"),
                     gen.const("Auto", int_t, 2, "Camera sets continuously"),
                     gen.const("Manual", int_t, 3, "Use explicit value"),
                     gen.const("OnePush", int_t, 4, "Camera sets once"),
                     gen.const("None", int_t, 5, "Feature not available")],
                    "Feature control states")

gen.add("auto_brightness", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Brightness control state.", 1, 0, 4, edit_method = controls)

gen.add("brightness", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Black level offset.", 0., 0., 4095.)

gen.add("auto_exposure", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Combined Gain, Iris & Shutter control.",
        1, 0, 4, edit_method = controls)

gen.add("exposure", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Auto exposure value (like contrast).", 0., -10., 4095.)

gen.add("auto_focus", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Focus control state.", 1, 0, 4, edit_method= controls)

gen.add("focus", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Focus control.", 0., 0., 4095.)

gen.add("auto_frame_rate_feature", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Frame rate state.", 1, 0, 4, edit_method= controls)

gen.add("frame_rate_feature", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Frame rate control.", 0., 0., 4095.)


gen.add("auto_gain", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Gain control state.", 1, 0, 4, edit_method = controls)

gen.add("gain", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Relative circuit gain.", 0., -10., 4095)

gen.add("auto_gamma", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Gamma control state.", 1, 0, 4, edit_method = controls)

gen.add("gamma", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Gamma expansion exponent.", 2.2, 0., 10.)

gen.add("auto_hue", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Hue control state.", 1, 0, 4, edit_method = controls)

gen.add("hue", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Color phase.", 0., 0., 4095.)

gen.add("auto_iris", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Iris control state.", 1, 0, 4, edit_method = controls)

gen.add("iris", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Iris control.", 8., 0., 4095.)

gen.add("auto_saturation", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Saturation control state.", 1, 0, 4, edit_method = controls)

gen.add("saturation", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Color saturation.", 1., 0., 4095.)

gen.add("auto_sharpness", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Sharpness control state.", 1, 0, 4, edit_method = controls)

gen.add("sharpness", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Image sharpness.", 1., 0., 4095.)

gen.add("auto_shutter", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Shutter control state.", 1, 0, 4, edit_method = controls)

gen.add("shutter", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Shutter speed.", 1., 0., 4095.)

gen.add("auto_white_balance", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "White balance control state.", 1, 0, 4, edit_method = controls)

gen.add("white_balance_BU", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Blue or U component of white balance.",
        0., 0., 4095.)

gen.add("white_balance_RV", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Red or V component of white balance.",
        0., 0., 4095.)

gen.add("auto_zoom", int_t, SensorLevels.RECONFIGURE_RUNNING,
        "Zoom control state.", 1, 0, 4, edit_method = controls)

gen.add("zoom", double_t, SensorLevels.RECONFIGURE_RUNNING,
        "Zoom control.", 0., 0., 4095.)

exit(gen.generate("camera1394_asl", "Camera1394", "Camera1394"))
